# Maintainer: Gabriel Rauter <rauter.gabriel@gmail.com>

_realname=baobab
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=41.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
pkgdesc="A graphical directory tree analyzer (mingw-w64)"
url="https://wiki.gnome.org/Apps/DiskUsageAnalyzer"
depends=("${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
         "${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime"
         "${MINGW_PACKAGE_PREFIX}-libhandy"
         "${MINGW_PACKAGE_PREFIX}-librsvg")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-yelp-tools"
             "${MINGW_PACKAGE_PREFIX}-appstream-glib"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-meson")
options=('strip' 'staticlibs')
license=("GPL2")
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"
        "0001-Fix-application-icon-name-in-baobab-main-window.ui.patch"
        "0001-Open-directory-in-explorer.patch")
sha256sums=('cad6278d2dcc80c84b57105aa5bb58d8a30ce98d6fabd767519ddb86c857e855'
            '53b44512790623b318c07584ea72c85acaf5c1280c00dde8969e863010cb183c'
            '5373f48a42f48adb951f7eefe0330034f865f91e736ad8e54f29206b971df18e')

prepare() {
    cd "${_realname}-${pkgver}"
    # https://gitlab.gnome.org/GNOME/baobab/-/merge_requests/23
    patch --forward --strip=1 --input="${srcdir}/0001-Fix-application-icon-name-in-baobab-main-window.ui.patch"
    patch --forward --strip=1 --input="${srcdir}/0001-Open-directory-in-explorer.patch"
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix=${MINGW_PREFIX} \
    --buildtype=plain \
    "../${_realname}-${pkgver}"

  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}" ninja install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
